import React, { PureComponent } from 'react'
const ThemeContext = React.createContext() // 创建上下文对象
// 两种Context传值
//   class.contextType
class MyButton extends PureComponent {
  // 使用 class.contextType 获取值
  // 通过 this.context 就可以获取到
  static contextType = ThemeContext
  render () {
    return (
      <>
         <button>按钮</button> { this.context }
      </>
    )
  }
}

class ToolBar extends PureComponent {
  render () {
    return (
      <MyButton></MyButton>
    )
  }
}

export default class App extends PureComponent {
  state = { theme: 'dark'}
  render() {
    return (
      // Context.Provider 传递数据只能使用 value 属性
      <ThemeContext.Provider value={ this.state.theme }>
        <ToolBar/>
      </ThemeContext.Provider>
    )
  }
}

